package cn.clementine.core.utils;

import cn.clementine.core.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLSyntaxErrorException;

@Slf4j
@RestControllerAdvice
public class ExceptionHandler {

    @org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
    public Result exceptionHandler(Exception e){
        log.error(e.toString());
        return Result.fail("server error");
    }
    @org.springframework.web.bind.annotation.ExceptionHandler(IllegalArgumentException.class)
    public Result ResultHandleIllegalArgumentException(IllegalArgumentException ex) {
        log.error(ex.toString());
        return Result.fail(ex.getMessage());
    }
    @org.springframework.web.bind.annotation.ExceptionHandler(BadSqlGrammarException.class)
    public Result ResultBadSqlGrammarException(BadSqlGrammarException ex) {
        log.error(ex.toString());
        return Result.fail(ex.getMessage());
    }
    @org.springframework.web.bind.annotation.ExceptionHandler(SQLSyntaxErrorException.class)
    public Result ResultBadSqlGrammarException(SQLSyntaxErrorException ex) {
        log.error(ex.toString());
        return Result.fail(ex.getMessage());
    }
}